﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;
using Dominio;

namespace Persistencia
{
    public class SubCategoria_Data
    {
        SqlConnection _cn = null;
        SqlCommand _cmd = null;
        SqlDataReader _reader = null;

        public List<SubCategoria> Data_Categoria_List(int codigoCategoria)
        {
            using (_cn = new SqlConnection(Helpers.ConexionUtil.ObtenerCadena()))
            {
                using (_cmd = new SqlCommand("USP_SUBCATEGORIA_LIST", _cn))
                {
                    List<SubCategoria> _ListSubCategorias = new List<SubCategoria>();
                    _cn.Open();
                    _cmd.CommandType = System.Data.CommandType.StoredProcedure;
                    _cmd.Parameters.Add("@coCategoria", SqlDbType.Int).Value = codigoCategoria;
                    _reader = _cmd.ExecuteReader();

                    while (_reader.Read())
                    {
                        SubCategoria _SubCategoria = new SubCategoria();
                        _SubCategoria.coSubCategoria = Convert.ToInt32(_reader["coSubCategoria"].ToString());
                        _SubCategoria.noSubCategoria = _reader["noSubCategoria"].ToString();
                        _ListSubCategorias.Add(_SubCategoria);
                    }
                    return _ListSubCategorias;
                }
            }
        }
    }
}
